package top.lilele.adminSystem.utils;

import lombok.extern.slf4j.Slf4j;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密类
 *
 * @Author: li.leLe
 * @Date: 2021/7/28 12:52
 */
@Slf4j
public class DigestUtil {
    public static String set(String content,String digestMethod) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance(digestMethod);
        //SHA-1
        md.update(content.getBytes(StandardCharsets.UTF_8));
        byte[] result = md.digest();
        String finalContent = new BigInteger(1, result).toString(16);
        log.info("获取加密之后的密文{}", finalContent);
        return finalContent;
    }
}
